import {Dictionary, FunCache} from "../types/Types";
import {generateUUID} from "../function/CommonUtils";

export class CallBackFunCache implements FunCache{
    cache: Dictionary<Function> = {};
    private _called: Dictionary<Function> = {};


    public cacheAndConvert(func:Function):string{
        let name:string=generateUUID();
        this.cache[name] = func;
        return 'cache.'+name;
    }

    public removeFunc(namespace:string){
        let namespaces: string[] = namespace.split(".");
        let name: string | undefined = namespaces.pop();
        let func: Function = this.cache[<string>name];
        this._called[<string>name] = func;
        delete this.cache[<string>name];
    }

}